package serviceset2

import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification

class InventorySpec extends Specification implements DomainUnitTest<Inventory> {

    def setup() {
        new Goods(name: "motor g", brand: "motor", price: 11.2).save()
    }

    def cleanup() {
    }

    void "test a valid properties"() {
        given:
        def params = [goods: Goods.get(1), count: 10L]

        when:
        def inventoryInstance = new Inventory(params)
        inventoryInstance.save()

        then:
        !inventoryInstance.hasErrors()
    }

    void "test an invalid properties"() {
        given:
        def params = [goods: Goods.get(999), count: -1L]

        when:
        def inventoryInstance = new Inventory(params)
        inventoryInstance.save()

        then:
        inventoryInstance.hasErrors()
        inventoryInstance.errors.allErrors.size() == 2
    }
}
